<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('入库单据列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>单据状态：</label>
                                <select id="status" name="status" th:height="300px">
                                    <!--<option value="">-&#45;&#45;请选择-&#45;&#45;</option>-->
                                    <option value="1" selected="selected">入库开单</option>
                                    <option value="2">已审核</option>
                                    <option value="3">收货确认</option>
                                    <option value="4">单据执行</option>
                                    <option value="5">执行完成</option>
                                    <option value="6">单据确认</option>
                                    <option value="7">单据作废</option>
                                    <option value="8">回传完成</option>
                                </select>
                            </li>
                            <li>
                                <label>入库类型：</label>
                                <select name="inType" id="inType" required>
                                    <!--<option value="">所有</option>-->
                                    <!--<option th:each="item:${inOrOutTypeList}"-->
                                            <!--th:value="${item.inOrOut}" th:text="${item.inOrOutTypeName}">-->
                                    <!--</option>-->
                                </select>
                            </li>
                            <li>
                                <label>单据号：</label>
                                <input type="text" name="stockinId" id="stockinId">
                            </li>
<!--                            <li>-->
<!--                                <label>单据号：</label>-->
<!--                                <input type="text" name="stockinId" id="stockinGuid">-->
<!--                            </li>-->
                            <!--                    <li>-->
                            <!--                        <option value="">请选择</option>-->
                            <!--                        <option th:each="item:${supplierList}"-->
                            <!--                                th:value="${item.supplierNo}" th:text="${item.supplierName}">-->
                            <!--                        </option>-->
                            <!--                        <lable>供应商：</lable>-->
                            <!--                        <input id="supplierId" name="supplierId" hidden>-->
                            <!--                        <input id="supplierName" name="supplierName" placeholder="请点击右侧按钮选择" readonly>-->
                            <!--                        <a id="selectSupplier" class="btn btn-success" onclick="selectSupplier()" >-->
                            <!--                            ...-->
                            <!--                        </a>-->
                            <!--                    </li>-->
                            <!--<li>-->
                                <!--<label>-->
                                    <!--单据来源：-->
                                <!--</label>-->

                                <!--<select id="stockinSource" name="stockinSource" required></select>-->
                            <!--</li>-->

                            <li>
                                <label>建单时间：</label>
                                <input type="text" placeholder="请单击选择开始时间：" name="startTime" id="startTime"/>---
                                <input type="text" placeholder="请单击选择结束时间：" name="finishTime" id="finishTime"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                        class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                        class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success btn-xs " onclick="audit()" shiro:hasPermission="stockin:stockin:audit">
                    <i class="fa fa-upload"></i> 单据审核
                </a>

                <a class="btn btn-success btn-xs" onclick="receiptSure()" shiro:hasPermission="stockin:stockin:reciptSure">
                    <i class="fa fa-download"></i> 单据确认
                </a>
                <a class="btn btn-danger" onclick="receiptCancle()" shiro:hasPermission="stockin:stockin:receiptCancle">
                    <i class="fa fa-trash-o"></i> 单据作废
                </a>


                <!--  <a class="btn btn-danger" onclick="printProduct()" shiro:hasPermission="mydo:stockinmanage:receiptCancle">
           <i class="fa fa-trash-o"></i> 打印物资条码
       </a>-->
            </div>
            <div id="div" style="height:350px" class="col-sm-8 select-table table-striped">
                <table id="bootstrap-table" data-mobile-responsive="true"></table>
            </div>
            <div id="div2" style="height:350px" class="col-sm-8 select-table table-striped">
                <table id="bootstrap-table2" data-mobile-responsive="true"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">

        //单据来源
        $(document).ready(function () {
            $.post("/bas/basType/list",{parentId:'08'},function(data){

                $("#stockinSource").append("<option value='' selected>全部</option>");
                // alert(data.rows[0].inOrOut);
                for(var i=0;i<data.total;i++){
                    $("#stockinSource").append("<option value="+data.rows[i].typeValue+">"+data.rows[i].typeName+"</option>");
                }
            });
        });

        //入库类型
        $(document).ready(function () {
            $.post("/bas/basType/list",{parentId:'03'},function(data){

                $("#inType").append("<option value='' selected>全部</option>");
                // alert(data.rows[0].inOrOut);
                for(var i=0;i<data.total;i++){
                    $("#inType").append("<option value="+data.rows[i].typeValue+">"+data.rows[i].typeName+"</option>");
                }
            });
        });

        layui.use('laydate', function () {
            var laydates = layui.laydate;
            laydates.render({
                elem: '#startTime'
                , type: 'datetime',
                /* ,range: '到' */
                format: 'yyyy-MM-dd HH:mm:ss'
            })
        })

        layui.use('laydate', function () {
            var laydates = layui.laydate;
            laydates.render({
                elem: '#finishTime'
                , type: 'datetime',
                /* ,range: '到' */
                format: 'yyyy-MM-dd HH:mm:ss'
            })
        })

        var prefix = ctx + "stockin/stockin";
        //子表
        var options2 = {
            url: "",
            singleSelect: true,
            search: false,
            showRefresh: true,
            showColumns: true,
            minimumCountColumns: 2,
            clickToSelect: true,//是否启用点击选中行
            // sortName: "assignNum",
            sortOrder: "desc",
            modalName: "入库单据子表",
            method: 'post',
            striped: true, //是否显示行间隔色
            pagination: true,//显示分
            pageNumber: 1,
            pageSize: 15,
            pageList: [10, 25],
            columns:
                [{
                    checkbox: true,
                },
                    {
                        field: 'stockinDetailId',
                        title: '子单编号'
                    },
                    {
                        field: 'stockinGuid',
                        title: 'sap订单号',
                        visible: false
                    },
                    {
                        field: 'stockinId',
                        title: '主单编号',
                        sortable: true
                    },
                    {
                        field: 'lotNo',
                        title: '批号',
                        visible: true
                    },

                    {
                        field: 'productGuid',
                        title: '物资名称'

                    },
                    {
                        field: 'productId',
                        title: '物品编号',
                        align: 'center'
                    },
                    {
                        field: 'remark',
                        title: '单位',
                        align: 'center'
                    },
                    {
                        field: 'quantity',
                        title: '计划数量',
                        visible: true
                    },
                    {
                        field: 'assignNum',
                        title: '实际数量',
                        visible: true
                    }




                ],
            onLoadSuccess(data) {
                switch (data.code) {
                    case  500:
                        options2.url = "";
                        $('#bootstrap-table2').bootstrapTable("removeAll")
                        $.modal.alertWarning("查询出错！");
                        break;
                    default:
                        break;
                }
            },
        }
        $('#bootstrap-table2').bootstrapTable(options2)


          //主表
            var options = {
                url: prefix + "/list",
                auditUrl: prefix + "/audit",
                receiptSureUrl: prefix + "/receiptSure",
                receiptCancleUrl: prefix + "/receiptCancle",
                detailView: false,//父子表
                search: false,
                singleSelect: true,
                showRefresh: true,
                showColumns: true,
                minimumCountColumns: 2,
                height: $("#div2").height() / 1,
                clickToSelect: true,//是否启用点击选中行
                sortName: "createDate",
                sortOrder: "desc",
                modalName: "入库单据",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'stockinGuid',
                    title: '交货单号'
                },
                {
                    field: 'stockinId',
                    title: '单据编号'
                },
                {
                    field: 'inType',
                    title: '入库类型',
                    formatter:function (value,row,index) {
                        if(value==1){
                            return "生产入库"
                        }else if(value==2){
                            return "采购入库"
                        }

                    }
                },
                {
                    field: 'createDate',
                    title: '创建时间'
                },
                // {
                //     field: 'supplierId',
                //     title: '供应商编号'
                // },
                // {
                //     field: 'customerId',
                //     title: '客户编号'
                // },
                {
                    field: 'createManId',
                    title: '建单人编号'
                },
                {
                    field: 'status',
                    title: '单据状态',
                    formatter: function (value, row, index) {
                        if (value == 1) {
                            return "入库开单";
                        } else if (value == 2) {
                            return "已审核";
                        } else if (value == 3) {
                            return "已收货";
                        } else if (value == 4) {
                            return "单据执行";
                        } else if (value == 5) {
                            return "执行完成";
                        } else if (value == 6) {
                            return "单据确认";
                        } else if (value == 7) {
                            return "单据作废";
                        } else if (value == 8) {
                            return "回传完成";
                        }

                    }
                },
                {
                    field: 'warehouseId',
                    title: '仓库编号'
                },
                {
                    field: 'stockinSource',
                    title: '单据来源',
                    formatter:function (value,row,index) {
                        if(value==0){
                            return "自建单"
                        }else if(value==1){
                            return "erp传单"
                        }
                    }

                },
                // {
                //     field: 'classNowId',
                //     title: '班组编号'
                // },
                // {
                //     field: 'lineId',
                //     title: '产线编号'
                // },
                {
                    field: 'finishDate',
                    title: '完成时间'
                },
                // {
                //     field: 'FID',
                //     title: 'fid'
                // }

                ],
                //双击显示子表
                onClickRow: function (t, e) {
                    // initSubTable(index, row, $detail);
                    options2.url = ctx + "stockindetail/stockindetail/list?stockinId=" + t.stockinId+"&status="+t.status;
                    $('#bootstrap-table2').bootstrapTable("refresh", options2)
                },
                onLoadSuccess(data) {
                    switch (data.code) {
                        case  500:
                            options2.url = "";
                            $('#bootstrap-table').bootstrapTable("removeAll");
                            $('#bootstrap-table2').bootstrapTable("removeAll");
                            $.modal.alertWarning("查询出错！");
                            break;
                        default:
                            $('#bootstrap-table2').bootstrapTable("removeAll");
                            break;
                    }
                },
            };
            $.table.init(options);

//单据审核
        function audit() {
            table.set();
            var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录！");
                return;
            }
            if (rows.length > 1) {
                $.modal.alertWarning("只允许选择一条记录！");
                return;
            }
            $.modal.confirm("确认要审核选中的" + rows.length + "条单据吗?", function () {
                var url = table.options.auditUrl;
                var data = {"ids": rows.join()};
                $.operate.submit(url, "post", "json", data);
            });
        }


//单据确认
        function receiptSure() {
            table.set();
            var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录！");
                return;
            }
            if (rows.length > 1) {
                $.modal.alertWarning("只允许选择一条记录！");
                return;
            }
            $.modal.confirm("确认要确认选中的" + rows.length + "条单据吗?", function () {
                var url = table.options.receiptSureUrl;
                var data = {"ids": rows.join()};
                $.operate.submit(url, "post", "json", data);
            });
        }
//单据作废
        function receiptCancle() {
            table.set();
            var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录！");
                return;
            }
            if (rows.length > 1) {
                $.modal.alertWarning("只允许选择一条记录！");
                return;
            }
            $.modal.confirm("确认要作废选中的" + rows.length + "条单据吗?", function () {
                var url = table.options.receiptCancleUrl;
                var data = {"ids": rows.join()};
                $.operate.submit(url, "post", "json", data);
            });
        }




    </script>
</body>
</html>